

//
//  YDRechargeSuccessViewController.m
//  PeiZiWangBei
//
//  Created by 巨彦新 on 2017/12/20.
//  Copyright © 2017年 LK-IOS. All rights reserved.
//

#import "YDRechargeSuccessViewController.h"
#import "YDRechargeWithdrawalButtonView.h"
#import "YDRechargeController.h"

@interface YDRechargeSuccessViewController ()<SYRechargeWithdrawalButtonViewDelegate>
@property (nonatomic, strong)YDRechargeWithdrawalButtonView *buttonView;
@property (nonatomic, strong)UIView *successView;
@end

@implementation YDRechargeSuccessViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setupNav];
    [self successView];
    [self buttonView];
    
}

- (void)setupNav
{
    self.title = @"充值";
    
 
}
#pragma mark - SYRechargeWithdrawalButtonViewDelegate
-(void)rechargeWithdrawalButtonViewButtonClick
{
//    [self.navigationController popToRootViewControllerAnimated:YES];
    
    UIViewController *vc = nil;

    NSArray *vcArr = self.drj_navigationController.drj_viewControllers;
    
    for (UIViewController *object in vcArr) {
        DDLog(@"object class = %@" , NSStringFromClass([object class]))
    }

    BOOL isMineVC  = [NSStringFromClass( [[vcArr firstObject] class]) isEqualToString:@"YDMineViewController"];

    if (isMineVC) {
        //从我界面过来 直接跳我的界面
        [self.navigationController popToRootViewControllerAnimated:YES];
        return;
    }else{
        //从其他界面跳过来 跳到充值上一个界面
        for (int i = 0; i < vcArr.count; i++) {
            
            vc = vcArr[i];
            
            if ([NSStringFromClass([vc class]) isEqualToString:@"YDRechargeController"])
            {
                //充值界面的上一个界面
                vc = vcArr[i - 1];
                [self.navigationController popToViewController:vc animated:YES];
                break;
            }else{
                [self.navigationController popToRootViewControllerAnimated:YES];
            }
            
        }
        
        
    }


    
}


- (UIView *)successView
{
    if (!_successView) {
        _successView = [UIView new];
        [self.view addSubview:_successView];
        [_successView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(isPhoneX ? @(rateX812(40)) : @(rate750(40)));
            make.centerX.equalTo(self.view);
            make.height.equalTo(isPhoneX ? @(rateX812(25)) : @(rate750(25)));
            make.width.equalTo(@(rate375(130)));
        }];
        UIImageView *image = [UIImageView new];
        image.contentMode = UIViewContentModeScaleAspectFit;
        image.image = [UIImage imageNamed:@"tixianchenggong"];
        [_successView addSubview:image];
        [image mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_successView.mas_left);
            make.centerY.equalTo(_successView);
        }];
        
        UILabel *tips = [UILabel new];
        [_successView addSubview:tips];
        [tips mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.right.bottom.equalTo(_successView);
            make.left.equalTo(image.mas_right).offset(rate375(9));
        }];
        tips.text = @"充值成功！";
        tips.textColor = [UIColor colorWithHexString:@"1E242E"];
        tips.font = [UIFont systemFontOfSize:font18ScreenWRate *LKScreenW];
        
    }
    return _successView;
}

-(YDRechargeWithdrawalButtonView *)buttonView
{
    if (_buttonView == nil) {
        YDRechargeWithdrawalButtonView *buttonView = [YDRechargeWithdrawalButtonView rechargeWithdrawalButtonWithButtonTitle:@"完成"];
        [buttonView enableButton];
        buttonView.delegate = self;
        [self.view addSubview:buttonView];
        
        [buttonView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self.view);
            if (isPhoneX) {
                make.height.equalTo(@(rateX812(63)));
            }else{
                make.height.equalTo(@(rate750(50)));
            }
        }];
        _buttonView = buttonView;
    }
    return _buttonView;
}

@end
